package com.flux.tms.tm${bean.numMain}srv.t${bean.numMain}${bean.numSub}.impl.service;

import static org.mockito.ArgumentMatchers.any;
import java.util.HashMap;
import java.util.Map;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.testng.annotations.Test;
<#if (bean.importDao)?size !=0>
<#list (bean.importDao)! as ipDao><#if (ipDao.name)?contains("Ctrl")>
    import com.flux.tms.tm${bean.numMain}srv.t${bean.numMain}${bean.numSub}.impl.Ctrl.${ipDao.name};
<#else >
import com.flux.tms.tm${bean.numMain}srv.t${bean.numMain}${bean.numSub}.impl.dao.${ipDao.name};
</#if> </#list>
</#if>
import com.flux.tms.tm${bean.numMain}srv.common.service.CommonService;
import com.flux.wmsv5.comobjs.LoginInfoObj;


/**
*
* 单元测试类: ${bean.fileName}
*
* 创建时间：${bean.dayTime}
*
* 修改时间：${bean.dayTime}
*
* @author YangSheng
*
* @version V1.0.0
*
*/
public class ${bean.fileName}Test extends CommonService {
    @InjectMocks
    private ${bean.fileName} ${bean.fileName};
<#if (bean.importDao)?size !=0>
<#list 0..((bean.importDao)?size-1) as i><#assign dao=(bean.importDao)[((bean.importDao)?size-1)].name2>
    @Mock
${(bean.importDao)[i].desc};
</#list>
    </#if>
    @SuppressWarnings("unchecked")
    @Test
    public void test() throws Exception {
        initLogin();
        initBizDataMap();
        ${bean.fileName} spy = PowerMockito.spy(${bean.fileName});
        Map<String, Object> tmpMap = new HashMap<String, Object>();

        //自己开始写方法

<#if (bean.serMethods)?size !=0>
    <#list (bean.serMethods)! as method>
        <#if (method.mName)??>
            <#if !((method.mName)?contains("post"))>
                <#if (method.mRetrun)=='void'>
        PowerMockito.doNothing().when(<#if (method.mReturnDesc)??>${method.mReturnDesc}</#if>
                <#else >
        PowerMockito.doReturn(<#if method.mRetrun=='int'>1<#elseif method.mRetrun=='boolean'||method.mRetrun=='Boolean'>true<#elseif (method.mRetrun)?contains("List")>dataList<#else >tmpMap</#if>).when(<#if (method.mReturnDesc)??>${method.mReturnDesc}</#if>
                </#if>
        <#--PowerMockito.doReturn(<#if method.mRetrun=='int'>1<#elseif method.mRetrun=='boolean'||method.mRetrun=='Boolean'>true<#elseif (method.mRetrun)?contains("List")>dataList<#else >tmpMap</#if>).when(<#if (method.mReturnDesc)??>${method.mReturnDesc}</#if>-->
        spy.${method.mName}(<#if (method.mParams)??><#list 0..((method.mParams)?size-1) as i><#if ((method.mParams)[i])?contains("Login") >loginInfoObj<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("List") >dataList<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("MapStr") >bizDataMap<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("MapObj") >dataMap<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("String[]") >new String[]{"1"}<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("String") >"ABC"<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("Boolean")||((method.mParams)[i])?contains("boolean") >true<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("int") >  0<#if i!= ((method.mParams)?size-1)>,</#if></#if></#list></#if>);
            <#else >
        <#--// 自己开始写postData的测试-->
        <#--spy.postData(<#if (method.mParams)??><#list 0..((method.mParams)?size-1) as i><#if ((method.mParams)[i])?contains("Login") >loginInfoObj<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("List") >dataList<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("MapStr") >bizDataMap<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("MapObj") >dataMap<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("String[]") >new String[]{"1"}<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("String") >"ABC"<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("Boolean")||((method.mParams)[i])?contains("boolean") >true<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("int") >  0<#if i!= ((method.mParams)?size-1)>,</#if></#if></#list></#if>);-->
            </#if>
        </#if>
    </#list>
</#if>
<#if (bean.serMethods)?size !=0>
    <#list (bean.serMethods)! as method>
        <#if (method.mName)??>
            <#if !((method.mName)?contains("post"))>
                <#else >

        PowerMockito.doReturn(1).when(${bean.daoName}).setTimeZone(any(LoginInfoObj.class));
                    <#if (bean.daoName)?contains("update")>
        PowerMockito.doReturn(1).when(${bean.daoName}).insertRulDisZoneArea1H(any(LoginInfoObj.class), any(Map.class), any(Map.class));
<#else >
        PowerMockito.doReturn(1).when(${bean.daoName}).insertRulDisZoneArea1H(any(LoginInfoObj.class), any(Map.class));</#if>
        // 前置报错
        PowerMockito.when(stdBizExtExecuteService.execute(any(LoginInfoObj.class), any(Map.class), any(String.class),
        any(String.class), Mockito.eq("POSTOPERATION_IN"))).thenReturn(reObjErr);
        spy.postData(<#if (method.mParams)??><#list 0..((method.mParams)?size-1) as i><#if ((method.mParams)[i])?contains("Login") >loginInfoObj<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("List") >dataList<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("MapStr") >bizDataMap<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("MapObj") >dataMap<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("String[]") >new String[]{"1"}<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("String") >"ABC"<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("Boolean")||((method.mParams)[i])?contains("boolean") >true<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("int") >  0<#if i!= ((method.mParams)?size-1)>,</#if></#if></#list></#if>);
        // 前置不报错，SQLcheck报错
        PowerMockito.when(stdBizExtExecuteService.execute(any(LoginInfoObj.class), any(Map.class), any(String.class),
        any(String.class), Mockito.eq("POSTOPERATION_IN"))).thenReturn(reObj);
         // 自己开始写postData的测试
        spy.postData(<#if (method.mParams)??><#list 0..((method.mParams)?size-1) as i><#if ((method.mParams)[i])?contains("Login") >loginInfoObj<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("List") >dataList<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("MapStr") >bizDataMap<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("MapObj") >dataMap<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("String[]") >new String[]{"1"}<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("String") >"ABC"<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("Boolean")||((method.mParams)[i])?contains("boolean") >true<#if i!= ((method.mParams)?size-1)>,</#if><#elseif  ((method.mParams)[i])?contains("int") >  0<#if i!= ((method.mParams)?size-1)>,</#if></#if></#list></#if>);
            </#if>
        </#if>
    </#list>
</#if>

}
    
    @Override
    protected CommonService returnSubClass() {
        return this;
    }

    @Override
    protected void initSubLogin() {
        
    }

    @Override
    protected void initSubBizDataMap() {
        
    }
    
}
